import { Component, Injector } from '@angular/core';
import { AppComponentBase } from '@abp/components';
import {
  AliStorageSettingEditDto,
  TencentStorageSettingEditDto,
  StorageSettingServiceProxy,
  StorageSettingEditDto,
} from '@abp/service-proxies/service-proxies';

@Component({
  templateUrl: './storage-settings.component.html',
  styleUrls: ['./storage-settings.component.less'],
})
export class StorageSettingComponent extends AppComponentBase {
  ossSetting: AliStorageSettingEditDto = new AliStorageSettingEditDto();
  cosSetting: TencentStorageSettingEditDto = new TencentStorageSettingEditDto();

  constructor(
    injector: Injector,
    private storageSettingService: StorageSettingServiceProxy,
  ) {
    super(injector);
  }

  ngOnInit(): void {
    this.storageSettingService
      .getAllSettings()
      .subscribe(storageSettingResult => {
        this.ossSetting = storageSettingResult.aliStorageSetting;
        this.cosSetting = storageSettingResult.tencentStorageSetting;
      });
  }

  submitForm() {
    let storage = new StorageSettingEditDto();
    storage.aliStorageSetting = this.ossSetting;
    storage.tencentStorageSetting = this.cosSetting;
    this.storageSettingService.updateAllSettings(storage).subscribe(result => {
      this.notify.success('保存成功！');
    });
  }
}
